
package nu.aing.P20140512;

import java.util.Arrays;

/**
 * GUA KAGAK NGARTI !!!!!!
 * 
 * @author memekmaut@gmail.com
 */
public class PiecewiseLinearFunctionDiv2 {

    public static void main(String[] args) {
        System.out.println(
                Arrays.toString(
                        countSolutions(
                                new int[] {1,4,-1,2}, 
                                new int[] {-2,-1,0,1}
                        ) 
                ) 
        );
        
        System.out.println(
                Arrays.toString(
                        countSolutions(
                                new int[] {0,0}, 
                                new int[] {-1,0,1}
                        ) 
                ) 
        );
        
    }

    public static int[] countSolutions(int[] Y, int[] query) {
        int[] results = new int[query.length];
        
        for (int i = 0; i < query.length; i++) {
            for (int j = 0; j < Y.length; j++) {
                if (query[i] == Y[j]) {
                    results[i]++;
                }
            }

            for (int j = 1; j < Y.length; j++) {
                if (query[i] == Y[j] && Y[j] == Y[j - 1]) {
                    results[i] = -1;
                    break;
                }
                
                if ((query[i] > Y[j - 1] && query[i] < Y[j]) || (query[i] < Y[j - 1] && query[i] > Y[j])) {
                    results[i]++;
                }
            }
        }
        return results;
    }
}
